﻿#include <QFile>
#include <QUrl>
#include "CHeader.h"
#include "CSqlOper.h"
#include "CPanItemDetailDlg.h"

CPanItemDetailDlg::CPanItemDetailDlg(QString sItemExecGuid, QString ItemName, QString sPointName, QWidget *parent)
	: m_sItemExecGuid(sItemExecGuid), m_sItemName(ItemName), m_sPointName(sPointName), QDialog(parent)
{
	ui.setupUi(this);
	setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
	setStyleSheetFile();
	m_mapUnit.insert(enIR, A2T("℃"));
	m_mapUnit.insert(enVoice, A2T("db"));
	m_mapUnit.insert(enCO, A2T("ppm"));
	m_mapUnit.insert(enGas, A2T("ppm"));
	m_mapUnit.insert(enPM25, A2T("ug/m3"));
	m_mapUnit.insert(enPM10, A2T("ug/m3"));
	m_mapUnit.insert(enTemp, A2T("℃"));
	m_mapUnit.insert(enHum, A2T("%RH"));
	m_mapUnit.insert(enCamer, A2T(""));
	m_mapUnit.insert(enUltrasonic, A2T(""));
	queryItem();
}

CPanItemDetailDlg::~CPanItemDetailDlg()
{}

void CPanItemDetailDlg::setStyleSheetFile()
{
	//设置对话框标题
	this->setWindowTitle(A2T("云台巡检项详情"));
	QString sQss = setUiStyle("styleSheet");
	QString sMyqss = styleSheet();
	QString sMerged = sQss + "\n" + sMyqss; // 后面的会覆盖前面的相同规则	
	setStyleSheet(sMerged);
}

void CPanItemDetailDlg::queryItem()
{
	ui.lineEditItemName->setText(m_sItemName);
	ui.lineEditPointName->setText(m_sPointName);
	QVector<QSqlRecord> vecRecord;
	QString sErrMsg = "";
	selectImageItemExecByItemExecID(m_sItemExecGuid, vecRecord, sErrMsg);
	for (int i = 0; i < vecRecord.size(); i++)
	{
		int nItemType = vecRecord[i].value("ITEM_TYPE_CODE").toInt();
		if (nItemType == enIR)
		{
			ui.lineEditTempMax->setText(vecRecord[i].value("TEMP_MAX").toString() + m_mapUnit[enIR]);
			ui.lineEditTempMin->setText(vecRecord[i].value("TEMP_MIN").toString() + m_mapUnit[enIR]);
			ui.lineEditTempAve->setText(vecRecord[i].value("TEMP_AGV").toString() + m_mapUnit[enIR]);
			ui.lineEditState->setText(vecRecord[i].value("IR_ALM_DESC").toString());
			ui.lineEditHH->setText(vecRecord[i].value("DATA_THRESHOLD_HH").toString() + m_mapUnit[enIR]);
			ui.lineEditH->setText(vecRecord[i].value("DATA_THRESHOLD_H").toString() + m_mapUnit[enIR]);
			ui.lineEditLL->setText(vecRecord[i].value("DATA_THRESHOLD_LL").toString() + m_mapUnit[enIR]);
			ui.lineEditL->setText(vecRecord[i].value("DATA_THRESHOLD_L").toString() + m_mapUnit[enIR]);
			ui.widget->InitUi(vecRecord[i].value("IR_URL").toString());
		}
		else if (nItemType == enVoice)
		{
			ui.label_3->hide();
			ui.lineEditTempMax->hide();
			ui.label_9->hide();
			ui.lineEditTempMin->hide();
			ui.label_8->setText(A2T("分贝值:"));
			ui.widget->hide();
			ui.lineEditTempAve->setText(vecRecord[i].value("VOICE_DATA").toString() + m_mapUnit[enVoice]);
			ui.lineEditState->setText(vecRecord[i].value("VOICE_DATA_STR").toString());
			ui.lineEditHH->setText(vecRecord[i].value("DATA_THRESHOLD_HH").toString() + m_mapUnit[enVoice]);
			ui.lineEditH->setText(vecRecord[i].value("DATA_THRESHOLD_H").toString() + m_mapUnit[enVoice]);
			ui.lineEditLL->setText(vecRecord[i].value("DATA_THRESHOLD_LL").toString() + m_mapUnit[enVoice]);
			ui.lineEditL->setText(vecRecord[i].value("DATA_THRESHOLD_L").toString() + m_mapUnit[enVoice]);
			ui.widget->hide();
		}
		else if (nItemType == enCamer)
		{
			ui.label_3->hide();
			ui.label_9->hide();
			ui.label_8->hide();
			ui.label_11->hide();
			ui.label_6->hide();
			ui.label_4->hide();
			ui.label_7->hide();
			ui.label_10->hide();
			ui.lineEditTempMax->hide();
			ui.lineEditTempMin->hide();
			ui.lineEditTempAve->hide();
			ui.lineEditState->hide();
			ui.lineEditHH->hide();
			ui.lineEditH->hide();
			ui.lineEditLL->hide();
			ui.lineEditL->hide();
			ui.widget->InitUi(vecRecord[i].value("IR_URL").toString());
		}
	}
}
